/**
 * 
 */
package due.pc.pcshoot.entity;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;

import android.content.Context;

public class Tank extends Sprite {
	// ===============================================================/
	// Constants
	// ===============================================================/
	public static final String IMAGEPATH = "gfx/tank_big.png";
	public static final int WIDTH = 64;
	public static final int HEIGHT = 128;

	public static final int CANON_SHOTS_DEFAULTAMONG = 5;

	// ===============================================================/
	// Fields
	// ===============================================================/
	private int mShotAmong = CANON_SHOTS_DEFAULTAMONG;

	// ===============================================================/
	// Constructors
	// ===============================================================/
	public Tank(float pX, float pY, TextureRegion pTextureRegion) {
		super(pX, pY, pTextureRegion);
	}

	// ===============================================================/
	// Inherited Methods
	// ===============================================================/

	// ===============================================================/
	// Methods
	// ===============================================================/

	// ===============================================================/
	// Getters & Setters
	// ===============================================================/
	public float[] getFirePoint() {
		return convertLocalToSceneCoordinates(WIDTH / 2, 0);
	}

	public int getShotAmong() {
		return mShotAmong;
	}

	public void setShotAmong(int pShotAmong) {
		this.mShotAmong = pShotAmong;
	}

	public void addShot(int pAmong) {
		mShotAmong += pAmong;
	}

	public boolean isShootable() {
		return mShotAmong > 0;
	}

	public void decreaseShotAmong() {
		mShotAmong--;
		if (mShotAmong < 0)
			mShotAmong = 0;
	}

	// ===============================================================/
	// Static Methods
	// ===============================================================/
	public static Tank create(float pX, float pY, Engine pEngine,
			Context pContext) {

		Texture texture = new Texture(WIDTH, HEIGHT,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		TextureRegion canonTextureRegion = TextureRegionFactory
				.createFromAsset(texture, pContext, IMAGEPATH, 0, 0);

		pEngine.getTextureManager().loadTexture(texture);

		return new Tank(pX, pY, canonTextureRegion);
	}
}
